<?php
/* *
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
*/
class companyaddress_controller extends company{
	function index_action(){
		include PLUS_PATH."/city.cache.php";
		$addcompanyaddress=$this->obj->DB_select_once("addcompanyaddress","`uid`='".$this->uid."' and `type` = '1'");
		$city=$city_name[$addcompanyaddress['provinceid']].'-'.$city_name[$addcompanyaddress['cityid']];
		if($addcompanyaddress['three_cityid']){
			$city.='-'.$city_name[$addcompanyaddress['three_cityid']];
		}
		$this->yunset("address",$addcompanyaddress['address']);
		$this->yunset("city",$city);		
		$urlarr['c']="companyaddress";
		$urlarr["page"]="{{page}}";
		$pageurl=Url('member',$urlarr);
		$this->get_page("addcompanyaddress","`uid`='".$this->uid."' and `type`='0' order by id desc",$pageurl,"12","`id`,`provinceid`,`cityid`,`three_cityid`,`address`");
		$sessionid=session_id();
		$this->yunset('city_name',$city_name);
		$this->yunset("sessionid",$sessionid);
		$this->public_action();
		$this->company_satic();
		$this->yunset("js_def",2);
		$this->com_tpl('companyaddress');
	}
	function del_action(){
		if($_GET['id']){
			$row=$this->obj->DB_select_once("addcompanyaddress","`id`='".(int)$_GET['id']."' and `uid`='".$this->uid."' and `type`='0'","`provinceid`");

			if(is_array($row)){
				unlink_pic(".".$row['provinceid']);
				$oid=$this->obj->DB_delete_all("addcompanyaddress","`id`='".(int)$_GET['id']."' and `uid`='".$this->uid."' and `type`='0'");
			}
			if($oid){
				$this->layer_msg('删除成功！',9,0,"index.php?c=companyaddress");
			}else{
				$this->layer_msg('删除失败！',8,0,"index.php?c=companyaddress");
			}
		}
	}
	function showpic_action(){
		if($_GET['id']){
			$this->public_action();
			$picurl=$this->obj->DB_select_once("company_show","`id`='".(int)$_GET['id']."' and `uid`='".$this->uid."'","`picurl`,`title`,`sort`");
			$this->yunset("picurl",$picurl);
			$this->yunset("uid",$this->uid);
			$this->yunset("id",$_GET['id']);
		    $this->yunset("js_def",2);
			$this->com_tpl('editshow');
		}
	}
	function delshow_action(){
		$ids = pylode(',',@explode(',',$_POST['ids']));
		$company_show=$this->obj->DB_select_all("company_show","`uid`='".$this->uid."' and `id` in (".$ids.")","`picurl`");
		if(is_array($company_show)&&$company_show){
			foreach($company_show as $val){
				unlink_pic(".".$val['picurl']);
			}
			$this->obj->DB_delete_all("company_show","`id` in (".$ids.") and `uid`='".$this->uid."'","");
			$this->obj->member_log("删除企业环境展示",16,3);
		}
		return true;
	}
	function address_action(){

		$this->public_action();
		$this->company_satic();
		$this->yunset($this->MODEL('cache')->GetCache(array('com','city','job','hy')));
		
		if($_GET['id']){
			$addcompanyaddressone=$this->obj->DB_select_once("addcompanyaddress","`id`='".$_GET['id']."' and `type` = '0' and `uid`='".$this->uid."'");
		}

		$this->yunset("row",$addcompanyaddressone);
		$this->yunset("uid",$this->uid);
		$this->yunset("js_def",2);
		$this->com_tpl('infoaddress');
	}
	function upshow_action(){
	    if ($_POST['picurl']!=''){
	        $show = $this->obj->DB_select_once('company_show',"`uid`='".$this->uid."'and `id`='".$_POST['id']."'");
	        if ($show['picurl']!=$_POST['picurl']){
	            $data['picurl'] = $this->checksrc($_POST['picurl'],$show['picurl']);
	        }
	    }
	    $data['title']=$_POST['title'];
	    $data['sort']=$_POST['showsort'];
	    $data['ctime']=time();
	    $companyM = $this->MODEL('company');
	    $nid = $companyM->UpdateShow($data,array('id'=>intval($_POST['id']),'uid'=>$this->uid));
	    if($nid){
	        $this->ACT_layer_msg("更新成功！",9,"index.php?c=show");
	    }else{
	        $this->ACT_layer_msg("更新失败！",8,"index.php?c=show");
	    }
	}
	 function save_action(){
		$_POST=$this->post_trim($_POST);
		if($_POST['provinceid']==""){
		    $this->ACT_layer_msg("所在地不能为空！",8);
		}
		if($_POST['address']==""){
		    $this->ACT_layer_msg("公司地址不能为空！",8);
		}

		if($_POST['companyaddresid']){
						$sql['uid']=$this->uid;
						$sql['provinceid']=$_POST['provinceid'];
						$sql['cityid']=$_POST['cityid'];
						$sql['three_cityid']=$_POST['three_cityid'];
						$sql['address']=$_POST['address'];
						$nid=$this->obj->update_once("addcompanyaddress",$sql,array('id'=>$_POST['companyaddresid']));
						if($nid){
							 $this->ACT_layer_msg("更新成功！",9,"index.php?c=companyaddress");
						}else{
							 $this->ACT_layer_msg("更新失败！",9,"index.php?c=companyaddress");
						}	
			}else{

				$sql['uid']=$this->uid;
				$sql['provinceid']=$_POST['provinceid'];
				$sql['cityid']=$_POST['cityid'];
				$sql['three_cityid']=$_POST['three_cityid'];
				$sql['address']=$_POST['address'];
				$nid=$this->obj->insert_into("addcompanyaddress",$sql);

				if($nid){
					$this->ACT_layer_msg("添加成功！",9,"index.php?c=companyaddress");
				}else{
					$this->ACT_layer_msg("添加失败！",9,"index.php?c=infoaddress");
				}
		}
		
	}
}
?>